package com.test.web.service;
import cn.hutool.core.util.IdUtil;
import com.he.core.ResultT;
import com.he.web.biz.CheckPage;
import com.test.web.dao.MenuDao;
import com.test.web.entity.Menu;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
/**
 * @author heyanjing
 * date:2020-07-21 2020/7/21:10:11
 */
@Service
public class MenuService {
    @Resource
    private MenuDao menuDao;
    public ResultT insert(Menu record) {
        record.setMenuId(IdUtil.simpleUUID());
        record.setStatus("valid");
        menuDao.insert(record);
        return ResultT.success();
    }
    public ResultT update(Menu record) throws Exception {
        Menu existMenu = menuDao.selectByPrimaryKey(record.getMenuId());
        CheckPage.set(existMenu, record);
        menuDao.updateByPrimaryKeySelective(existMenu);
        return ResultT.success();
    }
    public ResultT delete(String roleId) {
        List<String> idList = Arrays.asList(roleId.split(","));
        menuDao.updateStatusByMenuIdIn("del", idList);
        return ResultT.success();
    }
    public ResultT<List<Menu>> find() {
        List<Menu> menus = this.menuDao.find();
        return ResultT.successWithData(menus);
    }
    public ResultT<List<Menu>> list() {
        List<Menu> list = this.menuDao.findByStatus("valid");
        return ResultT.successWithData(list);
    }
}

